﻿// -----------------------------------------------------------------------
// <copyright file="ModelRautes.cs" company="">
// TODO: Update copyright text.
// </copyright>
// -----------------------------------------------------------------------

namespace RauteAdministarion.Models
{
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.ComponentModel;
    using System.Collections.ObjectModel;
    using RailroadDal;

    /// <summary>
    /// TODO: Update summary.
    /// </summary>
    public class ModelRautes : INotifyPropertyChanged
    {
        private ObservableCollection<Station> stations;
        private ObservableCollection<Distance> distances;

        public ObservableCollection<Distance> Distances
        {
            get
            {
                if (distances == null) 
                {
                    distances = new ObservableCollection<Distance>(RailroadDao.GetAllDistances());
                }
                return distances;
            }
      
        }

        public ObservableCollection<Station> Stations
        {
            get
            {
                if (stations == null)
                {
                    stations = new ObservableCollection<Station>(RailroadDao.GetAllStations());
                }
                return stations;
            }
            //set
            //{
            //    stations = value;
            //}
        }
        private void OnPropertyChanged(string propertyName)
        {
            if (this.PropertyChanged != null)
            {
                this.PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
            }
        }

        public void CreateStation(Station station) 
        {
            RailroadDao.CreateStation(station);

        }

        internal void ReloadStations()
        {
            this.Stations.Clear();
            stations = new ObservableCollection<Station>(RailroadDao.GetAllStations());
        }

        public void UpdateStation(Station station)
        {
            RailroadDao.UpdateStation(station,station.StationId);

        }

        public void DeleteStation(int stationId) 
        {
            RailroadDao.DeleteStation(stationId);

        }

        public void DeleteDistance(int distanceId) 
        
        {
            RailroadDao.DeleteDistance(distanceId);
        }

        public void UpdateDistances()
        {
            distances= new ObservableCollection<Distance>(RailroadDao.GetAllDistances());

        }

        public event PropertyChangedEventHandler PropertyChanged;
    }
}
